

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 参考资料 视频链接 运行环境  IDEA JDK8 SpringBoot 2.6.2  1. SpringBoot概述 1.1 Spring 缺点 配置繁琐 spring2.5 基于注解的组件扫描， 消除了大量针对应用程序自身组件显示的XML配置 spring3.0 引入了基于Java的配置、类型安全的可重构配置方式，可代替XML  依赖繁琐 在环境搭建时，需分析要导入哪些库的坐标，">
<meta property="og:type" content="article">
<meta property="og:title" content="SpringBoot 笔记1 SpringBoot 概述、快速入门、起步依赖原理分析、入门级配置">
<meta property="og:url" content="http://example.com/2022/01/06/SpringBoot%20%E7%AC%94%E8%AE%B01%20SpringBoot%20%E6%A6%82%E8%BF%B0%E3%80%81%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8%E3%80%81%E8%B5%B7%E6%AD%A5%E4%BE%9D%E8%B5%96%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90%E3%80%81%E5%85%A5%E9%97%A8%E7%BA%A7%E9%85%8D%E7%BD%AE/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 参考资料 视频链接 运行环境  IDEA JDK8 SpringBoot 2.6.2  1. SpringBoot概述 1.1 Spring 缺点 配置繁琐 spring2.5 基于注解的组件扫描， 消除了大量针对应用程序自身组件显示的XML配置 spring3.0 引入了基于Java的配置、类型安全的可重构配置方式，可代替XML  依赖繁琐 在环境搭建时，需分析要导入哪些库的坐标，">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/8a873604d8124f4b8330631e24adb1eb.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/7c8f093b726f4c33b69c3f58979ee686.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/63d6e67a43474b708c754f5ce7dfedd7.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/ca7c7353716146d8b665b4c919ae0bad.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/97dc48aa91874e63b13ce71c893a7894.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/98c0302996994367860926817de68a41.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/f07c9475d1d74913af05f8a9abea3447.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/0f2156bb27d843978d2d457b30886351.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/82264464a5c34bbc83a82e6b258dcfbd.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/aa88f5574fa74ceb9c8310ed2cf08f02.png#pic_center">
<meta property="article:published_time" content="2022-01-06T13:43:23.000Z">
<meta property="article:modified_time" content="2022-08-22T15:48:47.623Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="SpringBoot">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/8a873604d8124f4b8330631e24adb1eb.png#pic_center">
  
  
  
  <title>SpringBoot 笔记1 SpringBoot 概述、快速入门、起步依赖原理分析、入门级配置 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="SpringBoot 笔记1 SpringBoot 概述、快速入门、起步依赖原理分析、入门级配置"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-01-06 21:43" pubdate>
          2022年1月6日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          14k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          118 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">SpringBoot 笔记1 SpringBoot 概述、快速入门、起步依赖原理分析、入门级配置</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><hr>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1Lq4y1J77x?p=1">视频链接</a></p>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>IDEA</li>
<li>JDK8</li>
<li>SpringBoot 2.6.2</li>
</ul>
<h1 id="1-SpringBoot概述"><a href="#1-SpringBoot概述" class="headerlink" title="1. SpringBoot概述"></a>1. SpringBoot概述</h1><hr>
<h2 id="1-1-Spring-缺点"><a href="#1-1-Spring-缺点" class="headerlink" title="1.1 Spring 缺点"></a>1.1 Spring 缺点</h2><ul>
<li><p>配置繁琐</p>
<p>spring2.5 基于注解的组件扫描， 消除了大量针对应用程序自身组件显示的XML配置</p>
<p>spring3.0 引入了基于Java的配置、类型安全的可重构配置方式，可代替XML</p>
</li>
<li><p>依赖繁琐</p>
<p>在环境搭建时，需分析要导入哪些库的坐标，而且还要分析导入与之有依赖关系的其他库的坐标，一旦选错了依赖版本，随之而来的不兼容问题就会严重阻碍项目的开发进度。</p>
</li>
</ul>
<h2 id="1-2-SpringBoot功能"><a href="#1-2-SpringBoot功能" class="headerlink" title="1.2 SpringBoot功能"></a>1.2 SpringBoot功能</h2><ul>
<li><p>自动配置</p>
<p>Spring Boot的自动配置是一个运行时（即应用程序启动时）的过程，考虑了众多因素才决定Spring配置应该用哪个，不该用哪个，该过程是SpringBoot自动完成的。</p>
</li>
<li><p>起步依赖</p>
<p>本质上是一个Maven项目对象模型（Project Object Model，POM），定义了对其他库的传递依赖，整合后可支持某项功能。</p>
<p>简单的说，起步依赖就是将具备某种功能的坐标打包到一起，并提供一些默认的功能。</p>
</li>
<li><p>辅助功能</p>
<p>提供了一些大型项目中常见的非功能性特性，如嵌入式服务器，安全、指标、健康检测、外部配置等。</p>
</li>
</ul>
<p>Spring Boot 并不是对 Spring功能上的增强， 而是提供了一种 <strong>快速使用</strong> Spring的方式。</p>
<h2 id="1-3-小结"><a href="#1-3-小结" class="headerlink" title="1.3 小结"></a>1.3 小结</h2><p>SpringBoot提供了一种快速开发Spring项目的方式，并非是对Spring功能上的增强。</p>
<p>Spring的缺点：</p>
<ul>
<li>配置繁琐</li>
<li>依赖繁琐</li>
</ul>
<h1 id="2-SpringBoot-快速入门"><a href="#2-SpringBoot-快速入门" class="headerlink" title="2. SpringBoot 快速入门"></a>2. SpringBoot 快速入门</h1><hr>
<h2 id="2-1-使用案例"><a href="#2-1-使用案例" class="headerlink" title="2.1 使用案例"></a>2.1 使用案例</h2><p><strong>需求：</strong> 搭建SpringBoot工程，定义helloController.hello()方法，返回 “Hello SpringBoot!”</p>
<p><code>注意</code>：@SpringBootApplication标记的类必须在其他所有类的外层，否则启动会报错</p>
<p><img src="https://img-blog.csdnimg.cn/8a873604d8124f4b8330631e24adb1eb.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-2-实现步骤"><a href="#2-2-实现步骤" class="headerlink" title="2.2 实现步骤"></a>2.2 实现步骤</h2><ul>
<li><p>创建Maven项目</p>
</li>
<li><p>导入SpringBoot起步依赖</p>
</li>
</ul>
<p><code>pom.xml</code></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.example<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>Demo01<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.0-SNAPSHOT<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">properties</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">maven.compiler.source</span>&gt;</span>8<span class="hljs-tag">&lt;/<span class="hljs-name">maven.compiler.source</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">maven.compiler.target</span>&gt;</span>8<span class="hljs-tag">&lt;/<span class="hljs-name">maven.compiler.target</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">properties</span>&gt;</span><br>    <span class="hljs-comment">&lt;!-- SpringBoot工程需要继承的父工程 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.5.6<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span><br>        <span class="hljs-comment">&lt;!-- web 开发的起步依赖 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span><br></code></pre></td></tr></table></figure>



<ul>
<li>定义Controller</li>
</ul>
<p><code>hello.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller;<br><br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RestController;<br><br><br><span class="hljs-meta">@RestController</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">hello</span> &#123;<br>    <span class="hljs-meta">@RequestMapping(&quot;/hello&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">hello</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;hello,SpringBoot!&quot;</span>;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>编写引导类</li>
</ul>
<p><code>HelloApplication.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni;<br><br><span class="hljs-keyword">import</span> org.springframework.boot.SpringApplication;<br><span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;<br><br><span class="hljs-meta">@SpringBootApplication</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">HelloApplication</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        SpringApplication.run(HelloApplication.class, args);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>启动测试，访问 <code>localhost:8080/hello</code></li>
</ul>
<h2 id="2-3-使用-IDEA2021-快速创建SpringBoot项目"><a href="#2-3-使用-IDEA2021-快速创建SpringBoot项目" class="headerlink" title="2.3 使用 IDEA2021 快速创建SpringBoot项目"></a>2.3 使用 IDEA2021 快速创建SpringBoot项目</h2><p><img src="https://img-blog.csdnimg.cn/7c8f093b726f4c33b69c3f58979ee686.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>选择 SpringWeb</p>
<p><img src="https://img-blog.csdnimg.cn/63d6e67a43474b708c754f5ce7dfedd7.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>标记项目的src&#x2F;main下的java文件夹为 source（蓝色的文件夹），否则无法正常运行包下的Java类</p>
<p><img src="https://img-blog.csdnimg.cn/ca7c7353716146d8b665b4c919ae0bad.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>IDEA自动生成的pom依赖</p>
<p><code>pom.xml</code></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span> <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.6.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">relativePath</span>/&gt;</span> <span class="hljs-comment">&lt;!-- lookup parent from repository --&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.uni<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>demo02<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>0.0.1-SNAPSHOT<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>demo02<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">description</span>&gt;</span>Demo project for Spring Boot<span class="hljs-tag">&lt;/<span class="hljs-name">description</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">properties</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">java.version</span>&gt;</span>1.8<span class="hljs-tag">&lt;/<span class="hljs-name">java.version</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">properties</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span><br><br><span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span><br></code></pre></td></tr></table></figure>



<h2 id="2-3-小结"><a href="#2-3-小结" class="headerlink" title="2.3 小结"></a>2.3 小结</h2><ul>
<li><p>SpringBoot 在创建项目时，使用jar的打包方式</p>
</li>
<li><p>SpringBoot的引导类是项目入口，运行main方法就可以启动项目</p>
</li>
<li><p>使用SpringBoot和Spring构建的项目，业务代码编写方式完全一样</p>
</li>
</ul>
<h1 id="3-SpringBoot-起步依赖原理分析"><a href="#3-SpringBoot-起步依赖原理分析" class="headerlink" title="3. SpringBoot 起步依赖原理分析"></a>3. SpringBoot 起步依赖原理分析</h1><hr>
<p>spring-boot-starter-parent中定义了各种技术的版本信息，组合了一套最优搭配的技术版本</p>
<p>在各种stater中，定义了完成该功能需要的坐标合计，其中大部分版本信息来自于父工程</p>
<p>工程继承parent，引入starter后，通过依赖传递，可以简单方便的获得需要的jar包，且不会存在版本冲突等问题。</p>
<h1 id="4-SpringBoot配置"><a href="#4-SpringBoot配置" class="headerlink" title="4. SpringBoot配置"></a>4. SpringBoot配置</h1><hr>
<h2 id="4-1-配置文件分类"><a href="#4-1-配置文件分类" class="headerlink" title="4.1 配置文件分类"></a>4.1 配置文件分类</h2><p>SpringBoot是基于约定的，很多配置都有默认值，但若想使用自己的配置替换默认，可使用application.properties或者application.yml (&#x2F;.yaml) 进行配置</p>
<ul>
<li>properties</li>
</ul>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs properties"><span class="hljs-attr">server.prot</span>=<span class="hljs-string">8080</span><br></code></pre></td></tr></table></figure>

<ul>
<li>yml</li>
</ul>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs yml"><span class="hljs-attr">server:</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">8080</span><br></code></pre></td></tr></table></figure>



<p>在同一级目录下优先级（高 -&gt; 低）为 properties -&gt; yml -&gt; yaml</p>
<h2 id="4-2-yaml"><a href="#4-2-yaml" class="headerlink" title="4.2 yaml"></a>4.2 yaml</h2><p>yaml 全称是 <strong>yaml ain’t Markup Language</strong> 。 YAML是一种直观的能够被电脑识别的数据序列化格式，并且容器被人类阅读，容易和脚本语言交互，可被支持YAML库的不同的编程语言程序导入，比如：C&#x2F;C++、Ruby、Python、Java、Perl等。</p>
<p>YML文件是以数据为核心的，比传统的XML方式更简洁， YAML文件的扩展名可用.yml或.yaml</p>
<ul>
<li>properties</li>
</ul>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs properties"><span class="hljs-attr">server.port</span>=<span class="hljs-string">8080</span><br><span class="hljs-attr">server.address</span>=<span class="hljs-string">127.0.0.1</span><br></code></pre></td></tr></table></figure>

<ul>
<li>xml</li>
</ul>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">server</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">port</span>&gt;</span>8080<span class="hljs-tag">&lt;/<span class="hljs-name">port</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">address</span>&gt;</span>127.0.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">address</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">server</span>&gt;</span><br></code></pre></td></tr></table></figure>

<ul>
<li>yml</li>
</ul>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs yml"><span class="hljs-attr">server:</span><br>    <span class="hljs-attr">port:</span> <span class="hljs-number">8080</span><br>    <span class="hljs-attr">address:</span> <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span><br></code></pre></td></tr></table></figure>

<h3 id="基本语法"><a href="#基本语法" class="headerlink" title="基本语法"></a>基本语法</h3><ul>
<li>大小写敏感</li>
<li>数据值前边必须有空格，作为分隔符</li>
<li>使用缩进表示层级关系</li>
<li>缩进时<code>不允许</code>使用Tab键，只需用使用空格（各个系统Tab对应的空格数目可能不同，导致层次混乱)</li>
<li>缩进的空格数目不重要，只要相同层级的元素左侧对齐即可</li>
<li><code>#</code> 表示注释，从这个字符已知到行尾，都会被解析器忽略</li>
</ul>
<h3 id="YAML-数据格式"><a href="#YAML-数据格式" class="headerlink" title="YAML : 数据格式"></a>YAML : 数据格式</h3><ul>
<li>对象（map）: 键值对的集合</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">person:</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">uni</span><br><span class="hljs-comment"># 行内写法</span><br><span class="hljs-attr">person:</span> &#123;<span class="hljs-attr">name:</span> <span class="hljs-string">uni</span>&#125;<br></code></pre></td></tr></table></figure>



<ul>
<li>数组：一组按次序排列的值</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">address:</span><br>  <span class="hljs-bullet">-</span> <span class="hljs-string">hangzhou</span><br>  <span class="hljs-bullet">-</span> <span class="hljs-string">wenzhou</span><br><span class="hljs-comment"># 行内写法</span><br><span class="hljs-attr">address:</span> [<span class="hljs-string">hangzhou</span>, <span class="hljs-string">wenzhou</span>]<br></code></pre></td></tr></table></figure>

<ul>
<li>纯量： 单个的、不可再分的值</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">msg1:</span> <span class="hljs-string">&#x27;hello \n world&#x27;</span>  <span class="hljs-comment"># 单引忽略转义字符</span><br><span class="hljs-attr">msg2:</span> <span class="hljs-string">&quot;hello \n world&quot;</span>  <span class="hljs-comment"># 双引识别转义字符</span><br></code></pre></td></tr></table></figure>



<h3 id="YAML-参数引用"><a href="#YAML-参数引用" class="headerlink" title="YAML: 参数引用"></a>YAML: 参数引用</h3><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">name :</span> <span class="hljs-string">uni</span><br><br><span class="hljs-attr">person:</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">$&#123;name&#125;</span> <span class="hljs-comment"># 引用上面定义的name值</span><br></code></pre></td></tr></table></figure>



<h3 id="YAML-小结"><a href="#YAML-小结" class="headerlink" title="YAML: 小结"></a>YAML: 小结</h3><p><strong>配置文件类型</strong></p>
<ul>
<li>properties : 和以前一样</li>
<li>yml &#x2F; yaml : 注意空格</li>
</ul>
<p><strong>yaml</strong>: 简洁、以数据为核心</p>
<ul>
<li>基本语法<ul>
<li>大小写敏感</li>
<li>数值前必须有空格作为分隔符</li>
<li>使用空格缩进表示层级关系，相同缩进表示同一级</li>
</ul>
</li>
<li>数据格式<ul>
<li>对象</li>
<li>数组：使用”-“ 表示数组每个元素</li>
</ul>
</li>
<li>参数引用<ul>
<li><code>$&#123;key&#125;</code></li>
</ul>
</li>
</ul>
<h2 id="4-3-读取配置文件内容"><a href="#4-3-读取配置文件内容" class="headerlink" title="4.3 读取配置文件内容"></a>4.3 读取配置文件内容</h2><h3 id="4-3-1-Value"><a href="#4-3-1-Value" class="headerlink" title="4.3.1 @Value"></a>4.3.1 @Value</h3><p><code>application.yml</code></p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs yml"><span class="hljs-attr">name:</span> <span class="hljs-string">uni</span><br><br><span class="hljs-attr">student:</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">cc</span><br><br><span class="hljs-attr">address:</span><br>  <span class="hljs-bullet">-</span> <span class="hljs-string">hangzhou</span><br>  <span class="hljs-bullet">-</span> <span class="hljs-string">wenzhou</span><br></code></pre></td></tr></table></figure>



<p><code>HelloController.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller;<br><br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Value;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RestController;<br><br><span class="hljs-meta">@RestController</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">HelloController</span> &#123;<br>    <span class="hljs-meta">@Value(&quot;$&#123;name&#125;&quot;)</span><br>    <span class="hljs-keyword">private</span> String name_uni;<br><br>    <span class="hljs-meta">@Value(&quot;$&#123;student.name&#125;&quot;)</span><br>    <span class="hljs-keyword">private</span> String name_stu;<br><br>    <span class="hljs-meta">@Value(&quot;$&#123;address[0]&#125;&quot;)</span><br>    <span class="hljs-keyword">private</span> String addr;<br><br>    <span class="hljs-meta">@RequestMapping(&quot;/hello&quot;)</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">hello</span><span class="hljs-params">()</span>&#123;<br>        System.out.println(<span class="hljs-string">&quot;hello, I&#x27;m &quot;</span> + name_uni);<br>        System.out.println(<span class="hljs-string">&quot;I&#x27;m &quot;</span> + name_stu);<br>        System.out.println(<span class="hljs-string">&quot;城市: &quot;</span> + addr);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>



<h2 id="4-3-2-Environment"><a href="#4-3-2-Environment" class="headerlink" title="4.3.2 Environment"></a>4.3.2 Environment</h2><p>用和之前相同的yml文件</p>
<p><code>HelloController.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller;<br><br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Value;<br><span class="hljs-keyword">import</span> org.springframework.core.env.Environment;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RestController;<br><br><span class="hljs-meta">@RestController</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">HelloController</span> &#123;<br><br>    <span class="hljs-meta">@Autowired</span><br>    <span class="hljs-keyword">private</span> Environment env;<br><br>    <span class="hljs-meta">@RequestMapping(&quot;/hello&quot;)</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">hello</span><span class="hljs-params">()</span>&#123;<br>        System.out.println(<span class="hljs-string">&quot;hello, I&#x27;m &quot;</span> + env.getProperty(<span class="hljs-string">&quot;name&quot;</span>));<br>        System.out.println(<span class="hljs-string">&quot;I&#x27;m &quot;</span> + env.getProperty(<span class="hljs-string">&quot;student.name&quot;</span>));<br>        System.out.println(<span class="hljs-string">&quot;城市: &quot;</span> + env.getProperty(<span class="hljs-string">&quot;address[0]&quot;</span>));<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="4-3-3-ConfigurationProperties"><a href="#4-3-3-ConfigurationProperties" class="headerlink" title="4.3.3 @ConfigurationProperties"></a>4.3.3 @ConfigurationProperties</h3><p>此注解一个于标记某个类表示支持赋值配置文件里的内容</p>
<p>案例: 标记Student实体类</p>
<p><code>Student.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni;<br><br><span class="hljs-keyword">import</span> lombok.AllArgsConstructor;<br><span class="hljs-keyword">import</span> lombok.Data;<br><span class="hljs-keyword">import</span> lombok.NoArgsConstructor;<br><span class="hljs-keyword">import</span> org.springframework.boot.context.properties.ConfigurationProperties;<br><span class="hljs-keyword">import</span> org.springframework.stereotype.Component;<br><br><span class="hljs-meta">@NoArgsConstructor</span><br><span class="hljs-meta">@AllArgsConstructor</span><br><span class="hljs-meta">@Data</span><br><span class="hljs-meta">@Component</span><br><span class="hljs-meta">@ConfigurationProperties(prefix = &quot;student&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Student</span> &#123;<br>    <span class="hljs-keyword">private</span> String name;<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">int</span> age;<br>    <span class="hljs-keyword">private</span> String[] hobbys;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>spring-boot的配置 <code>application.yml</code></p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">student:</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">cc</span><br>  <span class="hljs-attr">age:</span> <span class="hljs-number">21</span><br>  <span class="hljs-attr">hobbys:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">跑步</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">睡觉</span><br></code></pre></td></tr></table></figure>

<p><code>HelloController.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller;<br><br><span class="hljs-keyword">import</span> com.uni.Student;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Value;<br><span class="hljs-keyword">import</span> org.springframework.core.env.Environment;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RestController;<br><br><span class="hljs-meta">@RestController</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">HelloController</span> &#123;<br>    <span class="hljs-meta">@Autowired</span><br>    <span class="hljs-keyword">private</span> Student student;<br>    <span class="hljs-meta">@RequestMapping(&quot;/stu&quot;)</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">stu</span><span class="hljs-params">()</span>&#123;<br>        System.out.println(student);<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>启动application，访问 <code>lcoalhost:8080/stu</code>，终端的结果为:</p>
<figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs reasonml"><span class="hljs-constructor">Student(<span class="hljs-params">name</span>=<span class="hljs-params">cc</span>, <span class="hljs-params">age</span>=21, <span class="hljs-params">hobbys</span>=[跑步, 睡觉])</span><br></code></pre></td></tr></table></figure>

<h2 id="4-4-profile"><a href="#4-4-profile" class="headerlink" title="4.4 profile"></a>4.4 profile</h2><p>作用：动态配置切换，解决Spring Boot应用开发，开发、测试、生产等不同环境下的配置切换问题</p>
<p>需要了解的内容：</p>
<ol>
<li>profile 配置方式<ul>
<li>多profile文件方式</li>
<li>yml多文档方式</li>
</ul>
</li>
<li>profile激活方式<ul>
<li>配置文件</li>
<li>虚拟机参数</li>
<li>命令行参数</li>
</ul>
</li>
</ol>
<h3 id="4-4-1-多profile文件配置"><a href="#4-4-1-多profile文件配置" class="headerlink" title="4.4.1 多profile文件配置"></a>4.4.1 多profile文件配置</h3><p><img src="https://img-blog.csdnimg.cn/97dc48aa91874e63b13ce71c893a7894.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h3 id="4-4-2-yml多文档方式"><a href="#4-4-2-yml多文档方式" class="headerlink" title="4.4.2 yml多文档方式"></a>4.4.2 yml多文档方式</h3><p>在<code>application.yml</code> 配置文件中以三个横岗— 划分一个文档区域，比如:</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs yml"><span class="hljs-meta">---</span><br><span class="hljs-attr">server:</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">8081</span><br><span class="hljs-meta">---</span><br></code></pre></td></tr></table></figure>



<p>案例：在一个yml文件中设置3个启动端口，并激活其中的1个服务器端口</p>
<p><code>application.yml</code></p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs yml"><span class="hljs-meta">---</span><br><span class="hljs-attr">server:</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">8081</span><br><span class="hljs-attr">spring:</span><br>  <span class="hljs-attr">config:</span><br>    <span class="hljs-attr">activate:</span><br>      <span class="hljs-attr">on-profile:</span> <span class="hljs-string">dev</span><br><span class="hljs-meta">---</span><br><span class="hljs-attr">server:</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">8082</span><br><span class="hljs-attr">spring:</span><br>  <span class="hljs-attr">config:</span><br>    <span class="hljs-attr">activate:</span><br>      <span class="hljs-attr">on-profile:</span> <span class="hljs-string">test</span><br><span class="hljs-meta">---</span><br><span class="hljs-attr">server:</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">8083</span><br><span class="hljs-attr">spring:</span><br>  <span class="hljs-attr">config:</span><br>    <span class="hljs-attr">activate:</span><br>      <span class="hljs-attr">on-profile:</span> <span class="hljs-string">pro</span><br><span class="hljs-meta">---</span><br><span class="hljs-meta"></span><br><span class="hljs-attr">spring:</span><br>  <span class="hljs-attr">profiles:</span><br>    <span class="hljs-attr">active:</span> <span class="hljs-string">test</span><br></code></pre></td></tr></table></figure>


<p><img src="https://img-blog.csdnimg.cn/98c0302996994367860926817de68a41.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h3 id="4-4-3-通过JVM虚拟机配置激活yml文档"><a href="#4-4-3-通过JVM虚拟机配置激活yml文档" class="headerlink" title="4.4.3 通过JVM虚拟机配置激活yml文档"></a>4.4.3 通过JVM虚拟机配置激活yml文档</h3><p>在IDEA设置<code>Run/Debug Configurations</code>中的 <code>vm options</code>参数</p>
<p>范例：激活yml里的test文档</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-attr">-Dspring.profiles.active</span>=test<br></code></pre></td></tr></table></figure>

<p>其中test是yml里通过三个横杠设置的一个文档配置，如下：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs yml"><span class="hljs-meta">---</span><br><span class="hljs-attr">server:</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">8082</span><br><span class="hljs-attr">spring:</span><br>  <span class="hljs-attr">config:</span><br>    <span class="hljs-attr">activate:</span><br>      <span class="hljs-attr">on-profile:</span> <span class="hljs-string">test</span><br><span class="hljs-meta">---</span><br></code></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/f07c9475d1d74913af05f8a9abea3447.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p><img src="https://img-blog.csdnimg.cn/0f2156bb27d843978d2d457b30886351.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h3 id="4-4-4-通过progarming参数激活yml文档"><a href="#4-4-4-通过progarming参数激活yml文档" class="headerlink" title="4.4.4 通过progarming参数激活yml文档"></a>4.4.4 通过progarming参数激活yml文档</h3><p>在IDEA设置<code>Run/Debug Configurations</code>中的 <code>programming options</code>参数</p>
<p>范例：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-attr">--spring.profiles.active</span>=test<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/82264464a5c34bbc83a82e6b258dcfbd.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h3 id="4-4-5-通过命令行在执行jar包时激活yml文档"><a href="#4-4-5-通过命令行在执行jar包时激活yml文档" class="headerlink" title="4.4.5 通过命令行在执行jar包时激活yml文档"></a>4.4.5 通过命令行在执行jar包时激活yml文档</h3><figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs mipsasm"><span class="hljs-keyword">java </span>-<span class="hljs-keyword">jar </span>打包后的.<span class="hljs-keyword">jar </span>--spring.profiles.active=test<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/aa88f5574fa74ceb9c8310ed2cf08f02.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h3 id="4-4-6-总结"><a href="#4-4-6-总结" class="headerlink" title="4.4.6 总结"></a>4.4.6 总结</h3><ul>
<li>profile是用来完成不同环境下，配置动态切换功能的</li>
<li>profile配置方式<ul>
<li>多profile文件方式：提供多个配置文件，每个代表一种环境<ul>
<li>application-dev.properties&#x2F;yml 开发环境</li>
<li>application-test.properties&#x2F;yml 测试环境</li>
<li>application-pro.properties&#x2F;yml 生产环境</li>
</ul>
</li>
<li>yml多文档方式<ul>
<li>在yml中使用 使用三个横杠— 分割不同配置</li>
</ul>
</li>
</ul>
</li>
<li>profile激活方式<ul>
<li>配置文件：在yml配置文件中 <code>spring.profiles.active=dev</code></li>
<li>虚拟机参数： 在VM opionts指定 <code>-Dspring.profiles.active=dev</code></li>
<li>命令行参数： <code>java -jar xxx.jar --spring.profiles.active=dev</code></li>
</ul>
</li>
</ul>
<h2 id="4-5-内部配置加载顺序"><a href="#4-5-内部配置加载顺序" class="headerlink" title="4.5 内部配置加载顺序"></a>4.5 内部配置加载顺序</h2><p>Springboot程序启动时，会从以下位置加载配置文件：</p>
<ul>
<li>file: .&#x2F;config&#x2F; : 当前目录下的&#x2F;config目录下</li>
<li>file:.&#x2F; : 当前项目的根目录</li>
<li>classpath:&#x2F;config&#x2F;: classpath的&#x2F;config目录</li>
<li>classpath: &#x2F; classpath的根目录</li>
</ul>
<p>加载顺序为上文的排列顺序，高优先级配置的属性会生效</p>
<h2 id="4-6-外部配置加载顺序"><a href="#4-6-外部配置加载顺序" class="headerlink" title="4.6 外部配置加载顺序"></a>4.6 外部配置加载顺序</h2><p>通过官网查看外部属性加载顺序</p>
<p><a target="_blank" rel="noopener" href="https://docs.spring.io/spring-boot/docs/2.6.2/reference/htmlsingle/#features.external-config">SpringBoot 官方Exernalized Configuration手册 </a></p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><code class="hljs awk"><span class="hljs-number">1</span>. Default properties (specified by setting `SpringApplication.setDefaultProperties`).<br><br><span class="hljs-number">2</span>. [`@PropertySource`](https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-framework/</span>docs<span class="hljs-regexp">/5.3.14/</span>javadoc-api<span class="hljs-regexp">/org/</span>springframework<span class="hljs-regexp">/context/</span>annotation/PropertySource.html) annotations on your `@Configuration` classes. Please note that such property sources are not added to the `Environment` until the application context is being refreshed. This is too late to configure certain properties such as `logging.*` and `spring.main.*` which are read before refresh begins.<br><br><span class="hljs-number">3</span>. Config data (such as `application.properties` files).<br><br><span class="hljs-number">4</span>. A `RandomValuePropertySource` that has properties only <span class="hljs-keyword">in</span> `random.*`.<br><br><span class="hljs-number">5</span>. OS environment variables.<br><br><span class="hljs-number">6</span>. Java System properties (`System.getProperties()`).<br><br><span class="hljs-number">7</span>. JNDI attributes from `java:comp/env`.<br><br><span class="hljs-number">8</span>. `ServletContext` init parameters.<br><br><span class="hljs-number">9</span>. `ServletConfig` init parameters.<br><br><span class="hljs-number">10</span>. Properties from `SPRING_APPLICATION_JSON` (inline JSON embedded <span class="hljs-keyword">in</span> an environment variable or system property).<br><br><span class="hljs-number">11</span>. Command line arguments.<br><br><span class="hljs-number">12</span>. `properties` attribute on your tests. Available on [`@SpringBootTest`]<br>(https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-boot/</span>docs<span class="hljs-regexp">/2.6.2/</span>api<span class="hljs-regexp">/org/</span>springframework<span class="hljs-regexp">/boot/</span>test<span class="hljs-regexp">/context/</span>SpringBootTest.html) and the [test annotations <span class="hljs-keyword">for</span> testing a particular slice of your application](https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-boot/</span>docs<span class="hljs-regexp">/2.6.2/</span>reference<span class="hljs-regexp">/htmlsingle/</span><span class="hljs-comment">#features.testing.spring-boot-applications.autoconfigured-tests).</span><br><br><span class="hljs-number">13</span>. [`@TestPropertySource`](https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-framework/</span>docs<span class="hljs-regexp">/5.3.14/</span>javadoc-api<span class="hljs-regexp">/org/</span>springframework<span class="hljs-regexp">/test/</span>context/TestPropertySource.html) annotations on your tests.<br><br><span class="hljs-number">14</span>. [Devtools global settings properties](https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-boot/</span>docs<span class="hljs-regexp">/2.6.2/</span>reference<span class="hljs-regexp">/htmlsingle/</span><span class="hljs-comment">#using.devtools.globalsettings) in the `$HOME/.config/spring-boot` directory when devtools is active.</span><br><br>Config data files are considered <span class="hljs-keyword">in</span> the following order:<br><br><span class="hljs-number">1</span>. [Application properties](https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-boot/</span>docs<span class="hljs-regexp">/2.6.2/</span>reference<span class="hljs-regexp">/htmlsingle/</span><span class="hljs-comment">#features.external-config.files) packaged inside your jar (`application.properties` and YAML variants).</span><br><br><span class="hljs-number">2</span>. [Profile-specific application properties](https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-boot/</span>docs<span class="hljs-regexp">/2.6.2/</span>reference<span class="hljs-regexp">/htmlsingle/</span><span class="hljs-comment">#features.external-config.files.profile-specific) packaged inside your jar (`application-&#123;profile&#125;.properties` and YAML variants).</span><br><br><span class="hljs-number">3</span>. [Application properties](https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-boot/</span>docs<span class="hljs-regexp">/2.6.2/</span>reference<span class="hljs-regexp">/htmlsingle/</span><span class="hljs-comment">#features.external-config.files) outside of your packaged jar (`application.properties` and YAML variants).</span><br><br><span class="hljs-number">4</span>. [Profile-specific application properties](https:<span class="hljs-regexp">//</span>docs.spring.io<span class="hljs-regexp">/spring-boot/</span>docs<span class="hljs-regexp">/2.6.2/</span>reference<span class="hljs-regexp">/htmlsingle/</span><span class="hljs-comment">#features.external-config.files.profile-specific) outside of your packaged jar (`application-&#123;profile&#125;.properties` and YAML variants).</span><br></code></pre></td></tr></table></figure>



<p>其中第十一种，在执行jar包时通过命令行指定 </p>
<figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs mipsasm"><span class="hljs-keyword">java </span>-<span class="hljs-keyword">jar </span>xxx.<span class="hljs-keyword">jar </span>--server.port=<span class="hljs-number">8082</span><br></code></pre></td></tr></table></figure>



<p>官网7.2.3 的example </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">java -jar myproject.jar --spring.config.location=\</span><br><span class="language-bash">    optional:classpath:/default.properties,\</span><br><span class="language-bash">    optional:classpath:/override.properties</span><br></code></pre></td></tr></table></figure>

<p>最常用的还是在jar包的同级目录下创建<code>application.properties</code>，比它优先级更高的是同级目录的config文件夹里的properties</p>
<p>可用于修改jar包内部一些配置，而且不影响项目其他的配置，特别方便</p>
<h1 id="5-总结"><a href="#5-总结" class="headerlink" title="5. 总结"></a>5. 总结</h1><hr>
<p>通过本次的学习，快速入门了 SpringBoot Web，简单的实现了 HelloWorld，同样是Web开发，跟之前的 Tomcat 部署相比，SpringBootWeb方便许多，只需要执行一个带有@SpringBootApplication注解的类，而且调用了SpringbootTestApplication方法就能启动一个web程序，而且不用配置web.xml</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> org.springframework.boot.SpringApplication;<br><span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;<br><br><span class="hljs-meta">@SpringBootApplication</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">SpringbootTestApplication</span> &#123;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        SpringApplication.run(SpringbootTestApplication.class, args);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>除此之外，笔者第一次接触了yml、yaml、propertries多种配置文件混合使用的情况，它们之间的优先级是 p &gt; yml &gt; yaml</p>
<p>通过Srping的注解方式简写了一个Controller层的类，之前都是继承一个HttpServlet然后使用@WebServlet进行编写，现在感觉方便很多，因为可以在同一个类里写多个方法用于响应不同地址的请求。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RestController</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">hello</span> &#123;<br>    <span class="hljs-meta">@RequestMapping(&quot;/hello&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">hello</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;hello,SpringBoot!&quot;</span>;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>起步依赖的部分有一点蒙，这应该属于Maven的知识，笔者没有系统学过Maven，现在暂时的理解就是它能像Java类一样去继承一个父类，然后Maven也可以实现这种继承，所以新建的SpringBootWeb项目里的pom.xml看起来较为简洁，其原因大概就是继承了封装好的一个Maven依赖，然后SpringBoot已经设计好了所有的依赖，现在可以直接使用。</p>
<p>综合以上，SpringBoot的使用并不复杂，但是对于其原理的理解则还需要进一步深入，同时需要花更多时间来熟练应用。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/SpringBoot/" class="category-chain-item">SpringBoot</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/SpringBoot/">#SpringBoot</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>SpringBoot 笔记1 SpringBoot 概述、快速入门、起步依赖原理分析、入门级配置</div>
      <div>http://example.com/2022/01/06/SpringBoot 笔记1 SpringBoot 概述、快速入门、起步依赖原理分析、入门级配置/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年1月6日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/01/07/Redis%20%E7%AC%94%E8%AE%B01%20%E5%AE%89%E8%A3%85%E4%BB%A5%E5%8F%8A%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/" title="Redis 笔记1 安装以及基本使用">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Redis 笔记1 安装以及基本使用</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/01/06/SpringMVC%20%E7%AC%94%E8%AE%B03%20%E6%8B%A6%E6%88%AA%E5%99%A8%E7%9A%84%E7%AE%80%E5%8D%95%E9%85%8D%E7%BD%AE%E4%B8%8E%E6%B5%8B%E8%AF%95/" title="SpringMVC 笔记3 拦截器的简单配置与测试">
                        <span class="hidden-mobile">SpringMVC 笔记3 拦截器的简单配置与测试</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
